// Released in the Public Domain. http://creativecommons.org/licenses/publicdomain/
package org.xi8ix.async;

import java.util.concurrent.Future;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.io.IOException;

/**
 * Defines the sending API exposed by all components that allow sending of messages.
 *
 * @author Iain Shigeoka
 */
public interface Sender {
    /**
     * Send data to a given destination sometime in the future. The future returned can be
     * used to check the status of the send operation, cancel the operation if the send is still
     * being processed, and obtain the success or failure of the send operation.
     *
     * @param dst destination for message
     * @param data the message to send
     * @return a future that can be used to check whether the send completed successfully or not. The future can
     * also be used to cancel the send operation if it has not already be completed or cancelled.
     */
    Future<Boolean> send(InetSocketAddress dst, ByteBuffer data);

    /**
     * Close the sender.
     */
    void close() throws IOException;

    /**
     * Obtain the current statistics for the sender.
     *
     * @return the statistics for the sender's performance.
     */
    Statistics getStatistics();

    /**
     * Obtain a tuner used to improve performance of the sender.
     *
     * @return the tuner used to tweak sender performance.
     */
    Tuner getTuner();
}
